package com.visizen.wisdomclass.server.client;

import com.visizen.wisdomclass.server.model.WcScore;
import com.visizen.wisdomclass.server.model.WcScoreExample;
import org.apache.ibatis.annotations.*;
import org.apache.ibatis.type.JdbcType;

import java.util.List;

public interface WcScoreMapper {
    /**
     * 查询指定学生的最近两次考试成绩
     *
     * @param userId
     * @return
     */
    @Select(" select * \n" +
            " from wc_score where user_id=#{userId}\n" +
            " order by score_id desc \n" +
            " limit 0,2;")
    List<WcScore> selectLatest2Scores(@Param("userId") Long userId);

    @Update("UPDATE wc_score SET score_value=#{score} WHERE score_id=#{scoreId}")
    int updateScoreById(@Param("scoreId") Long scoreId, @Param("score") int score);

    /**
     * This method was generated by MyBatis Generator. This method corresponds to the database table wc_score
     *
     * @mbggenerated
     */
    @SelectProvider(type = WcScoreSqlProvider.class, method = "countByExample")
    int countByExample(WcScoreExample example);

    /**
     * This method was generated by MyBatis Generator. This method corresponds to the database table wc_score
     *
     * @mbggenerated
     */
    @DeleteProvider(type = WcScoreSqlProvider.class, method = "deleteByExample")
    int deleteByExample(WcScoreExample example);

    /**
     * This method was generated by MyBatis Generator. This method corresponds to the database table wc_score
     *
     * @mbggenerated
     */
    @Delete({"delete from wc_score",
            "where score_id = #{score_id,jdbcType=BIGINT}"})
    int deleteByPrimaryKey(Long score_id);

    /**
     * This method was generated by MyBatis Generator. This method corresponds to the database table wc_score
     *
     * @mbggenerated
     */
    @Insert({
            "insert into wc_score (score_id, exam_id, ",
            "user_id, score_value)",
            "values (#{score_id,jdbcType=BIGINT}, #{exam_id,jdbcType=BIGINT}, ",
            "#{user_id,jdbcType=BIGINT}, #{score_value,jdbcType=INTEGER})"})
    int insert(WcScore record);

    /**
     * This method was generated by MyBatis Generator. This method corresponds to the database table wc_score
     *
     * @mbggenerated
     */
    @InsertProvider(type = WcScoreSqlProvider.class, method = "insertSelective")
    int insertSelective(WcScore record);

    @InsertProvider(type = WcScoreSqlProvider.class, method = "insertList")
    int insertList(@Param("records") List<WcScore> records);

    /**
     * This method was generated by MyBatis Generator. This method corresponds to the database table wc_score
     *
     * @mbggenerated
     */
    @SelectProvider(type = WcScoreSqlProvider.class, method = "selectByExample")
    @Results({
            @Result(column = "score_id", property = "score_id", jdbcType = JdbcType.BIGINT, id = true),
            @Result(column = "exam_id", property = "exam_id", jdbcType = JdbcType.BIGINT),
            @Result(column = "user_id", property = "user_id", jdbcType = JdbcType.BIGINT),
            @Result(column = "score_value", property = "score_value", jdbcType = JdbcType.INTEGER)})
    List<WcScore> selectByExample(WcScoreExample example);

    /**
     * This method was generated by MyBatis Generator. This method corresponds to the database table wc_score
     *
     * @mbggenerated
     */
    @Select({"select", "score_id, exam_id, user_id, score_value",
            "from wc_score", "where score_id = #{score_id,jdbcType=BIGINT}"})
    @Results({
            @Result(column = "score_id", property = "score_id", jdbcType = JdbcType.BIGINT, id = true),
            @Result(column = "exam_id", property = "exam_id", jdbcType = JdbcType.BIGINT),
            @Result(column = "user_id", property = "user_id", jdbcType = JdbcType.BIGINT),
            @Result(column = "score_value", property = "score_value", jdbcType = JdbcType.INTEGER)})
    WcScore selectByPrimaryKey(Long score_id);

    /**
     * This method was generated by MyBatis Generator. This method corresponds to the database table wc_score
     *
     * @mbggenerated
     */
    @UpdateProvider(type = WcScoreSqlProvider.class, method = "updateByExampleSelective")
    int updateByExampleSelective(@Param("record") WcScore record,
                                 @Param("example") WcScoreExample example);

    /**
     * This method was generated by MyBatis Generator. This method corresponds to the database table wc_score
     *
     * @mbggenerated
     */
    @UpdateProvider(type = WcScoreSqlProvider.class, method = "updateByExample")
    int updateByExample(@Param("record") WcScore record,
                        @Param("example") WcScoreExample example);

    /**
     * This method was generated by MyBatis Generator. This method corresponds to the database table wc_score
     *
     * @mbggenerated
     */
    @UpdateProvider(type = WcScoreSqlProvider.class, method = "updateByPrimaryKeySelective")
    int updateByPrimaryKeySelective(WcScore record);

    /**
     * This method was generated by MyBatis Generator. This method corresponds to the database table wc_score
     *
     * @mbggenerated
     */
    @Update({"update wc_score", "set exam_id = #{exam_id,jdbcType=BIGINT},",
            "user_id = #{user_id,jdbcType=BIGINT},",
            "score_value = #{score_value,jdbcType=INTEGER}",
            "where score_id = #{score_id,jdbcType=BIGINT}"})
    int updateByPrimaryKey(WcScore record);
}